﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Element.Net.Dialogs
{
    public enum LoadGifs
    {
        Load1,
        Load2,
        Load3,
        Load4,
    }

    public partial class LoadingDialog : Form
    {
        public LoadingDialog(Form parent, Action method, LoadGifs gif = LoadGifs.Load1)
        {
            InitializeComponent();
            InitLoadDialog(parent, method, gif);
        }

        private void InitLoadGif(LoadGifs gif)
        {
            switch (gif)
            {
                case LoadGifs.Load1:
                    pictureBox1.Image = Properties.Resources.load1;
                    break;
                case LoadGifs.Load2:
                    pictureBox1.Image = Properties.Resources.load2;
                    break;
            }
        }

        private void InitMethod(Action method)
        {
            new Task(() =>
            {
                method.Invoke();
                Invoke(new Action(() =>
                {
                    Close();
                    Dispose();
                }));
            }).Start();
        }

        private void InitLoadDialog(Form parent, Action method, LoadGifs gif)
        {
            ShowInTaskbar = false;
            InitLoadGif(gif);
            InitMethod(method);
            Width = parent.ClientRectangle.Width * 9 / 10;
            Height = parent.ClientRectangle.Height * 9 / 10;
            int width = (Width - pictureBox1.Width) / 2;
            int height = (Height - pictureBox1.Height) / 2;
            Point point = new Point(width, height);
            pictureBox1.Location = point;
        }
    }
}
